chown

In [3]:
ls -l ~/z
-rw-rw-r-- 1 milad milad 0 Dec 28 07:19 /home/milad/z
In [13]:
cat /etc/passwd | head -2
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
In [ ]:
sudo chown root ~/z
In [15]:
ls ~/z -l
-rw-rw-r-- 1 root adm 0 Dec 28 07:19 /home/milad/z
In [ ]:
sudo chown :root ~/z
In [1]:
ls -l ~/z
-rw-rw-r-- 1 root root 0 Dec 28 07:19 /home/milad/z
In [ ]:
sudo chown milad:milad z
In [2]:
ls -l ~/z
-rw-rw-r-- 1 milad milad 0 Dec 28 07:19 /home/milad/z

chmod

In [15]:
touch a b c
In [16]:
ls -la a b c
-rw-rw-rw- 1 milad milad 0 Dec 28 10:02 a
-rw-rw-rw- 1 milad milad 0 Dec 28 10:02 b
-rw-rw-rw- 1 milad milad 0 Dec 28 10:02 c

Analysis the meaning

In [28]:
chmod ugo+w [a-c]
In [23]:
ls -la [a-c]

stat -c "%a %n" [a-c]
-rw-rw-rw- 1 milad milad 0 Dec 28 10:02 a
-rw-rw-rw- 1 milad milad 0 Dec 28 10:02 b
-rw-rw-rw- 1 milad milad 0 Dec 28 10:02 c

666 a
666 b
666 c
In [29]:
chmod u+x,o-rw [a-c]
In [30]:
ls -la [a-c]
-rwxrw---- 1 milad milad 0 Dec 28 10:02 a
-rwxrw---- 1 milad milad 0 Dec 28 10:02 b
-rwxrw---- 1 milad milad 0 Dec 28 10:02 c
In [31]:
chmod 067 a
In [32]:
ls -la a
----rw-rwx 1 milad milad 0 Dec 28 10:02 a
In [33]:
chmod u+rw,o-rwx a
In [35]:
ls -la a
-rw-rw---- 1 milad milad 0 Dec 28 10:02 a

umask

The default permissions on

Files: 666 (Because we don't want files to have X by default) Directories: 777 (Because we need X to cd in)

In [37]:
umask
#files 664
#directories 775
0002
In [41]:
mkdir test
stat -c "%a %n" test
775 test

SUID, SGID

SUID

  • Files: executes with file owner permission
  • Directory : Nothing will happen
  • xyyy bit: 4

SGID

  • Files: executes with file group permission
  • Directories: new dirs will have the same group as parend dir
  • xyyy bit: 2

Sticky Bit

  • Files: Nothing will happen (Back in days: buffer in ram)
  • Directories: only the owner will be able to remove files
  • xyyy bit: 1
In [42]:
ls -ld /tmp
drwxrwxrwt 11 root root 4096 Dec 28 10:28 /tmp

Lecture notes

License

Creative Commons License

Linux Notes by Milad As (Ravexina) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.


ravexina's gitlab

ravexina's github